/*
* 通过类似于typeof age===”number“的判断语句，来改变Typescript的执行路径
* 在给定的执行路径中，我们可以缩小比声明时更小的类型，这个过程称之为缩小
* typeof age===”number“的判断语句可以称之为类型保护
*  常见的类型保护有：typeof、平等缩小(=== !==)、instanceof、 in等
* */
// typeof进行类型缩小
function getMessage(message) {
    if (typeof message === "number") {
        return message.toFixed(3);
    }
    else if (typeof message === "string") {
        return message.length;
    }
    else if (typeof message === "boolean") {
        return message;
    }
}
var res1 = getMessage(10);
console.log(res1);
var res2 = getMessage("typescript||JavaScript");
console.log(res2);
var res3 = getMessage(false);
console.log(res3);
function switchDirection(position) {
    switch (position) {
        case "left":
            return "left";
        case "right":
            return "right";
        case "bottom":
            return "bottom";
        case "top":
            return "top";
    }
}
var res4 = switchDirection("left");
console.log(res4);
function getDate(result) {
    if (result instanceof Date) {
        return result;
    }
    else {
        return result + 10;
    }
}
console.log(getDate(new Date()));
function move(animal) {
    if ("Swim" in animal) {
        animal.Swim();
    }
    else if ("Run" in animal) {
        animal.Run();
    }
}
var fish = {
    Swim: function () {
        console.log("游泳");
    }
};
var dog = {
    Run: function () {
        console.log("跑步");
    }
};
move(fish);
move(dog);
